<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col :span="4" :xs="24">
        <el-row :gutter="10" class="mb8" ref="hMain">
          <el-col :span="1.5">
            <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="treeHandleAdd">新增</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="success" plain icon="el-icon-edit" size="mini" @click="treeHandleUpdate">修改</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" plain icon="el-icon-delete" size="mini" @click="treeHandleDelete">删除</el-button>
          </el-col>
        </el-row>
        <div class="head-container" :style="{ height: treeHeight + 'px' }" style="overflow: auto">
          <el-tree :data="deptOptions" :props="defaultProps" :expand-on-click-node="false" ref="tree" node-key="id"
            default-expand-all highlight-current @node-click="handleNodeClick" :filter-node-method="filterNode"
            :default-expanded-keys="expandedkeys" :current-node-key="currentNodekey" :style="size" />
        </div>
      </el-col>
      <el-col :span="20" :xs="24">
        <el-tabs v-if="!isfondsCode" type="border-card" v-model="activeName" :style="{ height: tableHeight + 'px' }">
          <el-tab-pane label="无数据" name="first">
            <el-empty description=" " style="margin-top:10%;"></el-empty>
          </el-tab-pane>
        </el-tabs>
        <el-tabs v-else v-model="activeName" type="border-card" @tab-click="handleTabClick">
          <el-tab-pane label="门类信息" name="first">
            <ul class="first" ref="firstForm" :model="firstForm">
              <li><label>门类名称：</label>{{ firstForm.name }}</li>
              <li><label>门类代码：</label>{{ firstForm.code }}</li>
              <!--                            <li><label>全&#160;宗&#160;号：</label>北京市某某局</li>-->
              <li><label>档案库类型：</label>{{ firstForm.storeType }}</li>
              <li><label>整理方式：</label>{{ firstForm.type }}</li>
              <li><label>上架方式：</label>{{ firstForm.storeMode }}</li>
              <li><label>原文类型：</label>
                <el-checkbox-group v-model="firstForm.fileTypes">
                  <el-checkbox disabled v-for="dict in dict.type.TYPE" :label="dict.value" :key="dict.value">{{
                    dict.label }}</el-checkbox>
                </el-checkbox-group>
              <label>备&#160;注：</label>{{ firstForm.remark }}</li>
            </ul>
          </el-tab-pane>
          <el-tab-pane label="元数据方案信息" name="second">
            <el-form ref="secondForm" :rules="rulesForm" :model="secondForm" label-width="200px" style="margin-top:30px">
              <el-form-item label="方案名称" prop="name">
                <el-select ref="name" v-model="secondForm.name" placeholder="请选择方案" :disabled="isNameDisabled"
                  @change="changeSelectTap($event)">
                  <el-option v-for="item in nameOption" :key="item.value" :label="item.label"
                    :value="item.value"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="文件添加/修改页面列数" prop="wjcls">
                <el-select v-model="secondForm.wjcls" placeholder="请选择列数">
                  <el-option v-for="item in colNumOption" :key="item.value" :label="item.label"
                    :value="item.value"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="案卷添加/修改页面列数" prop="ajcls" v-show="isShowAj()">
                <el-select v-model="secondForm.ajcls" placeholder="请选择列数">
                  <el-option v-for="item in colNumOption" :key="item.value" :label="item.label"
                    :value="item.value"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="项目添加/修改页面列数" prop="xmcls" v-show="isShowXm()">
                <el-select v-model="secondForm.xmcls" placeholder="请选择列数">
                  <el-option v-for="item in colNumOption" :key="item.value" :label="item.label"
                    :value="item.value"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="submitForm">保存</el-button>
              </el-form-item>
            </el-form>
          </el-tab-pane>
          <el-tab-pane label="档号定义" name="third">
            <el-row :gutter="10" class="mb8">
              <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" @click="roleHandleAdd"
                  :disabled="isDisabledRule">新增规则</el-button>
              </el-col>
              <el-col :span="1.5">
                <el-button type="success" plain icon="el-icon-edit" @click="roleHandleUpdate"
                  :disabled="isDisabledRule">修改</el-button>
              </el-col>
              <el-col :span="1.5">
                <el-button type="danger" plain icon="el-icon-delete" :disabled="multiple"
                  @click="roleHandleDelete">删除</el-button>
              </el-col>
            </el-row>
            <el-table v-loading="loading" :data="roleList" @selection-change="handleSelectionChangeThird">
              <el-table-column type="selection" width="55" align="center" />
              <el-table-column label="序号" type="index" :index="table_index" prop="id" />
              <el-table-column label="名称" prop="name" :show-overflow-tooltip="true" />
              <el-table-column label="开始时间" prop="starttime">
                <template slot-scope="scope">
                  {{ scope.row.starttime }}
                </template>
              </el-table-column>
              <el-table-column label="结束时间" prop="endtime">
                <template slot-scope="scope">
                  {{ scope.row.endtime }}
                </template>
              </el-table-column>
              <el-table-column label="是否默认" prop="isMoren">
                <template slot-scope="scope">
                  {{ scope.row.isMoren == '1' ? '是' : '否' }}
                </template>
              </el-table-column>
              <el-table-column label="规则明细" prop="roleSort">
                <template slot-scope="scope">
                  <el-button type="text" icon="el-icon-s-grid" @click="classifyTap()">分类方法</el-button>
                  <el-button type="text" icon="el-icon-plus" @click="detailHandleAdd(scope.row)"
                    v-show="scope.row.fColumnname === null">新增</el-button>
                  <el-button type="text" icon="el-icon-edit" @click="detailHandleUpdate(scope.row)"
                    v-show="scope.row.fColumnname !== null">修改</el-button>
                </template>
              </el-table-column>
            </el-table>
            <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
              :limit.sync="queryParams.pageSize" @pagination="getThirdList" />
          </el-tab-pane>
          <el-tab-pane label="应用定义" name="fourth">
            <el-form :model="queryParam" ref="queryForm" size="small" :inline="true" v-show="showSearch"
              label-width="68px">
              <el-form-item label="模块名称" prop="menuName">
                <el-input v-model="queryParam.menuName" placeholder="请输入模块名称" clearable style="width: 240px"
                  @keyup.enter.native="handleQuery" />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
              </el-form-item>
            </el-form>
            <el-row :gutter="10" class="mb8">
              <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="applyHandleAdd">新增模块</el-button>
              </el-col>
              <el-col :span="1.5">
                <el-button type="danger" plain icon="el-icon-delete" size="mini"
                  @click="applyHandleDelete">删除模块</el-button>
              </el-col>
              <el-col :span="1.5">
                <el-button plain icon="el-icon-document-copy" size="mini" @click="applyHandleCopy">复制到</el-button>
              </el-col>
              <right-toolbar :showSearch.sync="showSearch" @queryTable="getApplyList"></right-toolbar>
            </el-row>
            <el-table v-loading="loading" :data="applyList" @selection-change="handleSelectionChange">
              <el-table-column type="selection" width="55" align="center" />
              <el-table-column label="序号" type="index" :index="table_index_apply" prop="MENU_ID" />
              <el-table-column label="模块名称" prop="MENU_NAME" :show-overflow-tooltip="true" />
              <el-table-column label="列表展示(列)" prop="roleKey" :show-overflow-tooltip="true">
                <template slot-scope="scope">
                  <el-button size="mini" type="text" icon="el-icon-plus"
                    @click="enableTap(scope.row, 'show')">启用</el-button>
                </template>
              </el-table-column>
              <el-table-column label="添加展示" prop="roleSort">
                <template slot-scope="scope">
                  <el-button size="mini" type="text" icon="el-icon-plus"
                    @click="enableTap(scope.row, 'add')">启用</el-button>
                </template>
              </el-table-column>
              <el-table-column label="修改展示" prop="roleSort">
                <template slot-scope="scope">
                  <el-button size="mini" type="text" icon="el-icon-plus"
                    @click="enableTap(scope.row, 'update')">启用</el-button>
                </template>
              </el-table-column>
              <el-table-column label="导出展示" prop="roleSort">
                <template slot-scope="scope">
                  <el-button size="mini" type="text" icon="el-icon-plus"
                    @click="enableTap(scope.row, 'export')">启用</el-button>
                </template>
              </el-table-column>
              <el-table-column label="查询条件" prop="roleSort">
                <template slot-scope="scope">
                  <el-button size="mini" type="text" icon="el-icon-plus"
                    @click="enableTap(scope.row, 'query')">启用</el-button>
                </template>
              </el-table-column>
              <el-table-column label="数据展示(行)" prop="roleSort">
                <template slot-scope="scope">
                  <el-button size="mini" type="text" icon="el-icon-plus"
                    @click="enableTap(scope.row, 'data')">启用</el-button>
                </template>
              </el-table-column>
            </el-table>
            <pagination v-show="applyTotal > 0" :total="applyTotal" :page.sync="queryParam.pageNum"
              :limit.sync="queryParam.pageSize" @pagination="getApplyList" />
          </el-tab-pane>
          <el-tab-pane label="归档范围和保管期限表" name="sex">
            <el-row :gutter="20">
              <el-col :span="5" :xs="24">
                <el-row :gutter="10" class="mb8" ref="hMain">
                  <el-col :span="1.5">
                    <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="treeZdAdd">新增</el-button>
                  </el-col>
                  <el-col :span="1.5">
                    <el-button type="success" plain icon="el-icon-edit" size="mini" @click="treeZdUpdate">修改</el-button>
                  </el-col>
                  <el-col :span="1.5">
                    <el-button type="danger" plain icon="el-icon-delete" size="mini" @click="treeZdDelete">删除</el-button>
                  </el-col>
                </el-row>

                <div class="head-container" style="overflow: auto">
                  <el-tree :data="gdfwandOptions" :props="defaultProps" :expand-on-click-node="false" ref="tree"
                    node-key="id" default-expand-all highlight-current @node-click="gdfwandNodeClick"
                    :filter-node-method="filterNode" :default-expanded-keys="expandedkeys"
                    :current-node-key="currentNodekey" :style="isSize" />
                </div>
              </el-col>
              <el-col :span="19" :xs="24">
                <el-table :data="tableZdData" border style="width: 100%">
                  <el-table-column type="index" label="序号" width="50" align="center" header-align="center">
                  </el-table-column>
                  <el-table-column prop="name" label="条款" width="500">
                  </el-table-column>
                  <el-table-column prop="bgqx" label="保管期限">
                    <template slot-scope="scope">
                      <div>
                        <span v-for="(i, idx) in dict.type.BGQX" :key="idx">
                          {{ scope.row.bgqx == i.value ? i.label : '' }}
                        </span>

                      </div>
                    </template>
                  </el-table-column>
                  <el-table-column prop="address" label="操作">
                    <template slot-scope="scope">
                      <el-button type="primary" plain icon="el-icon-s-tools" round size="mini"
                        @click="setRuleTap(scope.row)">设置规则</el-button>
                    </template>
                  </el-table-column>
                </el-table>
              </el-col>
            </el-row>
          </el-tab-pane>
        </el-tabs>
      </el-col>
    </el-row>

    <!-- 门类树的添加或修改用户配置对话框 -->
    <el-dialog :title="treeTitle" :visible.sync="treeOpen" width="30%" style="margin-top:4%" append-to-body>
      <el-form ref="treeForm" :model="treeForm" :rules="treeRules" label-width="100px">
        <el-form-item label="门类名称" prop="name">
          <el-input v-model="treeForm.name" placeholder="请输入名称" maxlength="30" />
        </el-form-item>

        <el-form-item label="档案库类型" prop="storeType">
          <el-select v-model="treeForm.storeType" placeholder="请选择档案库类型" style="width: 100%" class="el-selectTree">
            <el-option v-for="item in storeTypeOption" :key="item.value" :label="item.label"
              :value="item.value"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="门类代码" prop="code">
          <el-input v-model="treeForm.code" placeholder="请输入门类代码" maxlength="30" />
        </el-form-item>

        <el-form-item label="整理方式" prop="type">
          <el-select v-model="treeForm.type" placeholder="请选择整理方式" style="width: 100%" class="el-selectTree"
            :disabled="isDisabled">
            <el-option v-for="item in typeOption" :key="item.value" :label="item.label" :value="item.value"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="上架方式" prop="storeMode">
          <el-select v-model="treeForm.storeMode" placeholder="请选择上架方式" style="width: 100%" class="el-selectTree"
            :disabled="isStoreModeDisabled">
            <el-option v-for="item in storeModeOption" :key="item.value" :label="item.label"
              :value="item.value"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="原文类型" prop="fileTypes">
          <el-checkbox-group v-model="treeForm.fileTypes">
            <el-checkbox v-for="dict in dict.type.TYPE" :label="dict.value" :key="dict.value">{{ dict.label
            }}</el-checkbox>
          </el-checkbox-group>
        </el-form-item>

        <el-form-item label="排序" prop="orderNo">
          <el-input-number style="width: 100%" v-model="treeForm.orderNo" controls-position="right" placeholder="请输入排序"
            :min="1" :max="500"></el-input-number>
        </el-form-item>

        <el-form-item label="备注" prop="remark">
          <el-input v-model="treeForm.remark" type="textarea" style="width: 100%" placeholder="请输入内容"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitTrreForm">保 存</el-button>
        <el-button @click="treeCancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 档号定义规则的新增或修改规则 -->
    <el-dialog :title="roleTitle" :visible.sync="roleOpen" width="25%" style="margin-top:8%" append-to-body>
      <el-form ref="roleForm" :model="roleForm" :rules="roleRules" label-width="100px">
        <el-form-item label="名称" prop="name">
          <el-input v-model="roleForm.name" placeholder="请输入名称" maxlength="30" />
        </el-form-item>

        <el-form-item label="开始时间" prop="starttime">
          <el-date-picker v-model="roleForm.starttime" type="date" placeholder="选择日期" format="yyyy-MM-dd"
            value-format="yyyyMMdd" style="width: 100%">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="结束时间" prop="endtime" style="width: 100%">
          <el-date-picker v-model="roleForm.endtime" type="date" placeholder="选择日期" format="yyyy-MM-dd"
            value-format="yyyyMMdd" style="width: 100%">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="创建人" prop="creator">
          <el-input v-model="roleForm.creator" maxlength="30" disabled />
        </el-form-item>

        <el-form-item label="创建时间" prop="CREATETIME">
          <el-date-picker v-model="roleForm.CREATETIME" type="date" placeholder="选择日期" value-format="yyyyMMdd"
            format="yyyy-MM-dd" style="width: 100%" disabled>
          </el-date-picker>
        </el-form-item>

        <el-form-item label="是否默认" prop="isMoren">
          <el-radio v-model="roleForm.isMoren" :label="1">是</el-radio>
          <el-radio v-model="roleForm.isMoren" :label="0">否</el-radio>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitRoleForm">保 存</el-button>
        <el-button @click="roleCancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 档号定义规则明细的新增或修改规则 -->
    <el-dialog title="档号规则明细" :visible.sync="detailOpen" width="52%" style="margin-top:8%" append-to-body>
      <el-form ref="detailForm" class="center-input" :model="detailForm">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="档号存储字段:" label-width="100px" prop="columnname">
              <el-select v-model="detailForm.columnname" placeholder="请选择档号存储字段">
                <el-option v-for="item in colOption" :key="item.id" :label="item.label" :value="item.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="规则字段位数:" label-width="100px" prop="digit">
              <el-input-number v-model="digit" @change="handleValueChange" @input="handleCountInput"
                controls-position="right"></el-input-number>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="10">
          <ul class="rule-main" v-show="isShowDh()" v-for="(item, index) in dropdowns" :key="index">

            <li class="select-model">
              <el-form-item label="" style="width:100%">
                <el-select v-model="ziduanStart[index]" placeholder="请选择">
                  <el-option v-for="item in ziduanSOption" :key="item.id" :label="item.label"
                    :value="item.value"></el-option>
                </el-select>
              </el-form-item>
            </li>
            <li class="fuhao-model">
              <el-form-item prop="fuhaoarr"><el-input v-model="fuhaoarr[index]" placeholder="请输入"></el-input>
              </el-form-item>
            </li>
          </ul>
          <ul class="rule-main" v-show="isShowDh()">
            <li class="select-model">
              <el-form-item label="" prop="ziduanEnd">
                <el-select v-model="ziduanEnd" placeholder="请选择">
                  <el-option v-for="item in ziduanEOption" :key="item.id" :label="item.label"
                    :value="item.value"></el-option>
                </el-select>
              </el-form-item>
            </li>
          </ul>
        </el-row>
        <el-row class="flex" v-show="isShowDh()">
          <el-col :span="10">
            <el-form-item label="(件号/页数)补零位数:" label-width="150px" prop="bulingarr">
              <el-input-number placeholder="请输入" v-model="detailForm.bulingarr" :min="1" :max="10"></el-input-number>

            </el-form-item>

          </el-col>
          <!-- <el-col :span="1"> <label style="height: 36px;line-height: 36px;">位</label></el-col> -->
        </el-row>
        <!--start 卷内件、项目  显示模块 -->
        <el-row :gutter="10" v-show="isShowAj()">
          <el-col :span="10">
            <el-form-item label="卷内文件层档号存储字段:" label-width="180px" prop="jiancunchuziduan">
              <el-select v-model="detailForm.jiancunchuziduan" placeholder="请选择">
                <el-option v-for="item in jianziduanOption" :key="item.id" :label="item.label"
                  :value="item.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="2">
            <el-form-item label="" prop="jianlianjie">
              <el-input placeholder="请输入" v-model="detailForm.jianlianjie"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="" prop="jianziduan">
              <el-select v-model="detailForm.jianziduan" placeholder="请选择">
                <el-option v-for="item in jianOption" :key="item.id" :label="item.label" :value="item.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="7">
            <el-form-item label="补零位数:" label-width="80px" prop="jianbuling">
              <el-input-number placeholder="请输入" v-model="detailForm.jianbuling" :min="1" :max="10"></el-input-number>
            </el-form-item>
          </el-col>

        </el-row>
        <!-- end -->
        <el-row :gutter="10">
          <el-col :span="10">
            <el-form-item label="电子全文层档号存储字段:" label-width="180px" prop="filecunchuziduan">
              <el-input controls-position="right" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="2">
            <el-input placeholder="#" disabled></el-input>
          </el-col>
        </el-row>
        <el-form-item class="flex margin-top-form">
          <el-button type="primary" @click="detailCancel">取消</el-button>
          <el-button type="primary" @click="submitDetail">确定</el-button>
          <el-button type="primary" @click="sortRestore" v-show="isRestore()">恢复默认值</el-button>
          <el-button type="primary" @click="detailSort">排序</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

    <!-- 档号定义规则明细排序的新增或修改规则 -->
    <transFer v-if="sortData.length > 0 && sortOpen" :title="title" :dataChecked="dataChecked" :cities="sortData"
      @determine="determine" @closeFilter="closeFilter" :roleDetail="roleDetail" :open="sortOpen" @detail="detail"
      @sortRestore="sortRestore"></transFer>

    <!-- 应用定义的新增模块或修改规则 -->
    <el-dialog title="新增模块" :visible.sync="applyOpen" width="45%" style="margin-top:8%" append-to-body>
      <el-form ref="applyForm" :model="applyForm" label-width="100px">
        <el-form-item label="模块名称" prop="menuName">
          <el-select v-model="applyForm.menuName" filterable multiple placeholder="请选择">
            <!--            <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">-->
            <!--            </el-option>-->
            <el-option v-for="item in applyOption" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="flex margin-top-form">
          <el-button type="primary" @click="submitApply">确定</el-button>
          <el-button @click="applyCancel" style="margin: 5px 10px 5px">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

    <el-dialog title="复制模块" :visible.sync="applyCopyOpen" width="45%" style="margin-top:8%" append-to-body>
      <el-form ref="applyCopyForm" :model="applyCopyForm" label-width="100px">
        <el-form-item label="模块名称" prop="menuName">
          <el-select v-model="applyCopyForm.menuName" multiple placeholder="请选择" filterable>
            <el-option v-for="item in applyOptionCopy" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="flex margin-top-form">
          <el-button type="primary" @click="submitCopyApply">确定</el-button>
          <el-button @click="applyCopyCancel" style="margin: 5px 10px 5px">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

    <transFer v-if="applyDetailOpen" :title="ApplyDetailTitle" :dataChecked="myDataChecked" :cities="ApplyDetailData"
      @determine="submitApplyDetail" @closeFilter="closeApply" :open="applyDetailOpen" :IsXmDetail="IsXmDetail"
      @XmDetail="XmDetail" :IsJuanDetail="IsJuanDetail" @JuanDetail="JuanDetail" :IsJianDetail="IsJianDetail"
      @JianDetail="JianDetail" :IsDzwjDetail="IsDzwjDetail" @DzwjDetail="DzwjDetail" :isShowOrder="isShowOrder">
    </transFer>
    <!-- 设置规则 -->
    <setRule v-if="setRuleOpen == true" :setRuleOpen="setRuleOpen" @closeSetRuleDialog="closeSetRuleDialog"
      :addParams="addParams"></setRule>
    <!-- 分类方法 -->
    <classify v-if="classifyOpen == true" :classifyOpen="classifyOpen" :deptOptionsRowType="deptOptionsRowType"
      @closeClassifyDialog="closeClassifyDialog" :addParams="addParams"></classify>
    <!-- 制度添加修改 -->
    <zdTreeDeit v-if="zdTreeDeitOpen == true" :zdTreeDeitOpen="zdTreeDeitOpen"
      @closezdTreeDeitDialog="closezdTreeDeitDialog" @submitzdTrreForm="submitzdTrreForm" :addParams="addParams">
    </zdTreeDeit>
  </div>
</template>
<script>
import {
  listGROUPTree,
  addGroupTree,
  getGroupTree,
  updateGroupTree,
  delGroupTree,
  metaData,
  saveMetaData,
  getMetaData,
  getCodeRule,
  addCodeRule,
  updateCodeRule,
  delCodeRole,
  metaList,
  listforshy2,
  addRoleDetail,
  roleDetailList,
  updateRoleDetail,
  getApply,
  addApply,
  delApply,
  delArrApply,
  copyApply,
  addApplyDetail, fieldlist, listMenu, getmdatalist, gdfwandbgqxTree, gdfwandbgqxEditzd2, getzd2, gettable
} from "@/api/manage/archivesCategory";
import transFer from "@/components/transFer/index.vue"
import { getInfo } from "@/api/login";
import estimateTableHeight from '@/mixins/estimateTableHeight'
import setRule from "@/views/archive/application/archivesCategory/setRule.vue"; //设置规则
import classify from "@/views/archive/application/archivesCategory/classify.vue"; //分类方法
import zdTreeDeit from "@/views/archive/application/archivesCategory/zdTreeDeit.vue"; //制度数添加修改
//vue项目中element-tabel自动计算高度
export default {
  components: {
    transFer,
    classify,
    zdTreeDeit,
    setRule
  },
  user_Dicts: ['SYS_NORMAL_DISABLE', 'TYPE', 'BGQX'],
  mixins: [estimateTableHeight], // 混入方法
  data() {
    const checkType = (rule, value, callback) => {
      if ((this.treeForm.type === '1' || this.treeForm.type === '3') && value === '') {
        callback(new Error('请选择上架方式'));
      } else {
        callback();
      }
    }
    const inputName = (rule, value, callback) => {
      if (value.trim() === '') {
        callback(new Error('输入不能为空格'));
      } else {
        callback();
      }
    }
    return {
      dataChecked: [],
      myDataChecked: [],
      roleDetail: true,
      IsXmDetail: false,
      IsJuanDetail: false,
      IsJianDetail: false,
      IsDzwjDetail: false,
      isShowOrder: false,
      title: "档号规则明细",
      //应用定义弹出层
      applyTitle: "应用定义明细",
      applyOption: [],
      sortData: [],
      // sortorder: [],
      input: "-",
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 档号表格数据
      roleList: [],
      // 应用定义表格数据
      applyList: [],
      // 部门树选项
      deptOptions: undefined,
      defaultProps: {
        children: "children",
        label: "label"
      },
      //tabs标签切换默认选择项
      activeName: 'first',
      //多选框是否勾选
      checkList: ['附件'],
      dialogFormVisible: true,
      //批量操作
      ticketsform: {
        isInput: false, //是否可录入
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 15
      },
      queryParam: {
        pageNum: 1,
        pageSize: 10,
        menuName: ""
      },
      //应用模块
      applyDetailData: [],
      ApplyDetailData: [],
      //默认展开的树节点
      expandedkeys: [],
      //默认选中的树节点
      currentNodekey: "",
      //门类树是否显示弹出层
      treeOpen: false,
      //门类树弹出层(标题)
      treeTitle: "",
      //档号定义规则是否显示弹出层
      roleOpen: false,
      //档号定义规则弹出层
      roleTitle: "",
      //档号定义规则明细是否显示弹出层
      detailOpen: false,
      //档号定义排序是否显示弹出窗
      sortOpen: false,
      //应用定义是否显示弹出层
      applyOpen: false,
      // 应用定义是否展示复制到弹出层
      applyCopyOpen: false,
      // 应用定义明细是否显示弹出层
      applyDetailOpen: false,
      //树表单参数
      treeForm: {
        name: undefined,
        storeType: undefined,
        code: undefined,
        type: null,
        storeMode: undefined,
        fileTypes: [],
        orderNo: undefined,
        remark: undefined
      },
      // 档号定义规则表单参数
      roleForm: {},
      // 档号定义规则明细表单参数
      detailForm: {},
      // 档号定义排序表单参数
      sortForm: {},
      digit: "",
      ziduanStart: [],
      fuhaoarr: [],
      ziduanEnd: "",
      // 应用定义表单参数
      applyForm: {},
      applyCopyForm: {},
      //门类整理方式：添加可以编辑，修改时禁止编辑
      isDisabled: false,
      //门类上架方式：添加可以编辑，修改时禁止编辑
      isStoreModeDisabled: false,
      // 元数据方案未保存可以选择,保存后禁止选择
      isNameDisabled: false,
      //树表单校验
      treeRules: {
        name: [
          { required: true, message: '门类名称不能为空', trigger: 'blur' },
          { trigger: 'blur', validator: inputName }
        ],
        storeType: [
          { required: true, message: '档案库类型不能为空' }
        ],
        code: [
          { required: true, message: '门类代码不能为空', trigger: 'blur' },
          {
            pattern: /^[A-Za-z0-9_·]+$/,
            message: "请输入数字、字母‘_’或‘·’",
            trigger: "blur"
          },
          { trigger: 'blur', validator: inputName }
        ],
        type: [
          { required: true, message: '整理方式不能为空' }
        ],
        storeMode: [
          { required: true, message: '上架方式不能为空' },
          // { trigger: 'blur', validator: checkType },
        ]
      },
      // 档号定义规则表单校验
      roleRules: {
        name: [
          { required: true, message: '名称不能为空', trigger: 'blur' }
        ],
        starttime: [
          { required: true, message: '开始时间不能为空', trigger: 'blur' }
        ],
        endtime: [
          { required: true, message: '结束时间不能为空', trigger: 'blur' }
        ]
      },
      // 门类树添加---档案库类型下拉
      storeTypeOption: [
        { value: 't', label: '文本类' },
        { value: 'p', label: '照片类' },
        { value: 'v', label: '视频类' },
        { value: 'm', label: '录音类' },
        { value: 'o', label: '其他类' },
        { value: 'l', label: '蓝图类' },
        { value: 'd', label: '底图类' },
        { value: 'j', label: '检察类' },
        { value: 'g', label: '过程文件类' }
      ],
      // 门类树添加---整理方式下拉
      typeOption: [
        { value: '1', label: '组卷' },
        { value: '0', label: '组件' },
        { value: '3', label: '项目' },
      ],
      // 门类树添加---原文类型
      // fileTypesOption: [
      //   { value: '1', label: '正文' },
      //   { value: '2', label: '文稿' },
      //   { value: '3', label: '报批件' },
      //   { value: '4', label: '附件' }
      // ],
      // 门类信息---上架方式
      storeModeOptions: [
        { value: '2', label: '按盒上架' },
        { value: '1', label: '按卷上架' }
      ],
      //元数据方案明细类型下拉
      deptOptionsRowType: undefined,
      fileTypes: [],
      // 门类表单参数
      firstForm: {},
      // 元数据方案信息参数
      secondForm: {},
      // 元数据方案
      nameOption: [],
      isDisabledRule: true,
      // 档号
      colOption: [],
      // 规则字段
      ziduanSOption: [],
      ziduanEOption: [],
      jianziduanOption: [],
      jianOption: [],
      // 下拉框的列表
      dropdowns: [],
      // 元数据方案type
      metaType: '',
      // 元数据方案---列数选择
      colNumOption: [
        { value: '2', label: '2' },
        { value: '3', label: '3' }
      ],
      // 非单个禁用
      ids: [],
      names: [],
      single: true,
      applySingle: true,
      applyName: [],
      // 非多个禁用
      multiple: true,
      applyMultiple: true,
      roleorder: 'asc', // 默认升序
      roleRowId: '',
      isarr: [], //判断
      operate: '',
      enableOperate: '',
      menuID: '',
      // 展示弹窗
      ApplyDetailTitle: "应用定义明细",
      //恢复默认值form
      restoreForm: {},
      //规则明细按钮标识
      fColumnname: "",
      flag: true,
      rulesForm: { //元数据方案信息校验
        name: [
          { required: true, message: '请选择方案', trigger: 'blur' },
        ],
      },
      isfondsCode: false, //判断如果是全宗就不显示右侧tabs的数据
      // 应用定义
      applyTotal: 0,
      size: "",
      classifyOpen: false, //分类方法弹窗
      addParams: "",
      zdTreeDeitOpen: false,//制度树添加修改
      setRuleOpen: false,//设置规则弹窗
      gdfwandOptions: undefined,//制度树列表
      parentId: undefined,//获取当前点击制度树的ID
      deitInfo: "",//制度树修改信息
      tableZdData: [],//制度列表
      applyOptionCopy: []
    }
  },
  created() {
    this.getDeptTree();
    if (this.$store.getters.size == 'small') {
      this.size = 'font-size: 12px;'
    } else {
      this.size = 'font-size: 14px;'
    }
  },
  computed: {
    storeModeOption() {
      if (this.treeForm.type == '0') {
        this.treeForm.storeMode = '2'
        return [{ value: '2', label: '按盒上架' }]
      } else {
        return [
          { value: '2', label: '按盒上架' },
          { value: '1', label: '按卷上架' }
        ]
      }
    },
    isSize() {

      if (this.$store.getters.size == 'small') {
        this.size = 'font-size: 12px;'
      } else {
        this.size = 'font-size: 14px;'
      }
      return this.size
    }
  },
  methods: {
    handleTabClick(tab) {
      if (tab.name == 'first') {
        this.getFirstList()
      } else if (tab.name == 'second') {
        this.getSecondList()
      } else if (tab.name == 'third') {
        this.getThirdList()
      } else if (tab.name == 'fourth') {
        this.getApplyMenu()
        this.getApplyList()
      } else {
        this.gdfwandbgqxTreePost();
      }
    },
    table_index(index) {
      return (this.queryParams.pageNum - 1) * this.queryParams.pageSize + index + 1;
    },
    table_index_apply(index) {
      return (this.queryParam.pageNum - 1) * this.queryParam.pageSize + index + 1;
    },
    isShowAj() {
      return this.metaType === '1' || this.metaType === '3'
    },
    isShowXm() {
      return this.metaType === '3'
    },
    isShowDh() {
      return this.digit > 0
    },
    isRestore() {
      if (this.operate == 'update') {
        return true;
      } else {
        return false;
      }
    },
    // 表单重置
    reset() {
      this.treeForm = {
        name: undefined,
        storeType: undefined,
        code: undefined,
        type: null,
        storeMode: undefined,
        fileTypes: [],
        orderNo: undefined,
        remark: undefined
      };
    },
    // 门类信息表单重置
    resetFirst() {
      this.firstForm = {
        name: undefined,
        code: undefined,
        storeType: undefined,
        type: null,
        storeMode: undefined,
        fileTypes: [],
        remark: undefined
      }
    },
    // 元数据方案信息表单重置
    resetSecond() {
      this.secondForm = {
        name: undefined,
        wjcls: undefined,
        ajcls: undefined,
        xmcls: undefined,
        type: undefined,
        id: undefined,
        groupId: undefined
      }
    },
    // 档号定义规则表单重置
    resetThird() {
      this.roleForm = {
        id: undefined,
        name: undefined,
        starttime: undefined,
        endtime: undefined,
        categoryModelId: undefined,
        creator: this.roleForm.creator,
        CREATETIME: this.roleForm.CREATETIME,
        isMoren: null
      }
    },
    // 档号定义规则明细表单重置
    resetRoleDetail() {
      this.detailForm = {
        columnname: undefined,
        bulingarr: undefined,
        jiancunchuziduan: "",
        jianlianjie: "",
        jianziduan: "",
        jianbuling: "",
        filelianjie: "#",
        order: undefined
      }
      this.ziduanStart = []
      this.fuhaoarr = []
      this.ziduanEnd = undefined
      this.digit = ""
    },
    // 获取门类信息渲染门类信息标签页
    getFirstList() {
      this.resetFirst();
      getGroupTree(this.queryParams.id).then(response => {
        this.firstForm = response.data;
        if (response.data.fileTypes !== null) {
          this.firstForm.fileTypes = response.data.fileTypes.split(',');
        } else {
          this.firstForm.fileTypes = []
        }
        const option = this.storeTypeOption.find(option => option.value === response.data.storeType);
        this.firstForm.storeType = option ? option.label : '';
        this.metaType = response.data.type.toString()
        this.getSecondList();
        const option1 = this.typeOption.find(option => option.value === response.data.type.toString());
        this.firstForm.type = option1 ? option1.label : '';
        const option2 = this.storeModeOptions.find(option => option.value === response.data.storeMode.toString());
        this.firstForm.storeMode = option2 ? option2.label : '';
      });
    },
    /** 查询树结构 */
    getDeptTree() {
      listGROUPTree().then(response => {
        this.deptOptions = response.data;
        if (this.deptOptions.length > 0) {
          this.currentNodeKey = this.deptOptions[0].children[0].id;
          this.expandedkeys.push(this.deptOptions[0].children[0].id);
          this.$nextTick(() => {
            this.$refs.tree.setCurrentKey(this.deptOptions[0].children[0].id)
          })
          // 门类id
          this.queryParams.id = response.data[0].children[0].id;
          // 元数据方案id
          this.queryParams.groupId = response.data[0].children[0].groupId
          if (response.data[0].children[0].groupId != null) {
            this.isDisabledRule = false; // 选择元数据方案后才可以操作档号规则
          } else {
            this.isDisabledRule = true
          }
          //获取树的type==null ,不显示右侧数据
          if (response.data[0].children[0].type != null) {
            this.isfondsCode = true
            if (this.deptOptions[0].children[0].type == 0) {
              this.deptOptionsRowType = [
                { value: '0', label: '件层' },
                { value: '2', label: '电子文件层' },
              ]
            } else if (this.deptOptions[0].children[0].type == 1) {
              this.deptOptionsRowType = [
                { value: '1', label: '卷层' },
                { value: '0', label: '件层' },

                { value: '2', label: '电子文件层' },
              ]
            } else {
              this.deptOptionsRowType = [
                { value: '3', label: '项目层' },
                { value: '1', label: '卷层' },
                { value: '0', label: '件层' },
                { value: '2', label: '电子文件层' },

              ]
            }
          }
          this.getFirstList();
          // this.getSecondList();
          this.getThirdList();


        }
      });
    },
    // 筛选节点
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    // 节点单击事件
    handleNodeClick(data) {
      this.isfondsCode = data.type == null ? false : true; //判断右侧模块显示无数据还是有数据
      console.log(data, "shuju")
      //门类id
      this.queryParams.id = data.id;
      // 元数据方案id
      this.queryParams.groupId = data.groupId
      this.metaType = data.type
      if (this.isfondsCode) {
        this.activeName = 'first'
        this.getFirstList(); //获取门类信息渲染门类信息标签页
        this.getSecondList(); // 获取信息渲染元数据方案信息标签页
        this.getThirdList(); // 获取档号定义列表
        this.getApplyList(); // 获取应用定义表格数据
        this.getApplyTrans() //获取应用定义弹窗数据
      }
      // this.handleQuery();
      if (data.groupId != null) {
        this.isDisabledRule = false; // 选择元数据方案后才可以操作档号规则
      } else {
        this.isDisabledRule = true
      }

      if (data.type == 0) {
        this.deptOptionsRowType = [
          { value: '0', label: '件层' },
          { value: '2', label: '电子文件层' },
        ]
      } else if (data.type == 1) {
        this.deptOptionsRowType = [
          { value: '1', label: '卷层' },
          { value: '0', label: '件层' },

          { value: '2', label: '电子文件层' },
        ]
      } else {
        this.deptOptionsRowType = [
          { value: '3', label: '项目层' },
          { value: '1', label: '卷层' },
          { value: '0', label: '件层' },
          { value: '2', label: '电子文件层' },

        ]
      }
    },
    //档案门类树添加
    treeHandleAdd() {
      var that = this;
      that.treeOpen = true;
      this.isDisabled = false;
      this.isStoreModeDisabled = false
      that.treeTitle = "添加门类";
      this.reset();
    },
    //档案门类树修改
    treeHandleUpdate() {
      this.reset();
      getGroupTree(this.queryParams.id).then(response => {
        this.treeForm = response.data;
        if (response.data.fileTypes !== null) {
          this.treeForm.fileTypes = response.data.fileTypes.split(',');
        } else {
          this.treeForm.fileTypes = []
        }
        this.treeForm.type = response.data.type.toString();
        this.treeForm.storeMode = response.data.storeMode.toString();
        this.treeOpen = true;
        this.isDisabled = true;
        this.isStoreModeDisabled = true;
        this.treeTitle = "修改门类";
      });
    },
    //门类树添加提交
    submitTrreForm() {
      this.$refs["treeForm"].validate((valid) => {
        if (valid) {
          if (this.treeForm.id != null) {
            this.treeForm.fileTypes = this.treeForm.fileTypes.toString()
            this.treeForm.type = parseInt(this.treeForm.type)
            this.treeForm.storeMode = parseInt(this.treeForm.storeMode)
            updateGroupTree(this.treeForm).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.treeOpen = false;
              this.getDeptTree();
            });
          } else {
            this.treeForm.fileTypes = this.treeForm.fileTypes.toString()
            this.treeForm.type = parseInt(this.treeForm.type)
            this.treeForm.storeMode = parseInt(this.treeForm.storeMode)
            addGroupTree(this.treeForm).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.treeOpen = false;
              this.getDeptTree();
            });
          }
        }
      })
    },
    //门类树修改取消
    treeCancel() {
      var that = this;
      that.treeOpen = false;
    },
    //档号定义规则取消
    roleCancel() {
      this.roleOpen = false;
    },
    detailCancel() {
      this.detailOpen = false;
      this.sortOpen = false;
    },
    closeFilter() {
      this.detailOpen = false;
      this.sortOpen = false;
    },
    //档案门类树 删除
    treeHandleDelete() {
      var dataRow = this.deptOptions[0].children.filter((item) => {
        return item.id == this.queryParams.id
      })
      this.$modal.confirm('是否确认删除档案门类名称为"' + dataRow[0].label + '"的数据项？').then(function () {
        return delGroupTree(dataRow[0].id);
      }).then(() => {
        this.getDeptTree();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    // 获取元数据方案下拉框
    fetchData() {
      this.resetSecond();
      if (this.metaType != '') {
        this.form = {
          isUse: '0',
          type: this.metaType
        }
        metaData(this.form).then(response => {
          this.nameOption = response.data.map(option => {
            return {
              value: option.id,
              label: option.name,
              type: option.type
            }
          })
          if (this.nameOption.length > 0) {
            // this.secondForm.nameValue = this.nameOption[0].value;
            // this.secondForm.name = this.nameOption[0].label;
            // this.secondForm.groupId = this.nameOption[0].value;
            // this.secondForm.type = this.nameOption[0].type;
          }
          if (this.metaType === '0') {
            this.secondForm.wjcls = '2'
          } else if (this.metaType === '1') {
            this.secondForm.ajcls = '2'
            this.secondForm.wjcls = '2'
          } else if (this.metaType === '3') {
            this.secondForm.xmcls = '2'
            this.secondForm.ajcls = '2'
            this.secondForm.wjcls = '2'
          }
        })
      }
    },
    // 保存元数据方案信息
    submitForm() {

      this.$refs.secondForm.validate((valid) => {
        if (valid) {
          this.secondForm.id = this.queryParams.id;
          if (this.metaType == '0') {
            this.secondForm.wjcls = parseInt(this.secondForm.wjcls)
            this.secondForm.ajcls = 0;
            this.secondForm.xmcls = 0;
          } else if (this.metaType == '1') {
            this.secondForm.xmcls = 0
            this.secondForm.ajcls = parseInt(this.secondForm.ajcls)
            this.secondForm.wjcls = parseInt(this.secondForm.wjcls)
          } else {
            this.secondForm.ajcls = parseInt(this.secondForm.ajcls)
            this.secondForm.wjcls = parseInt(this.secondForm.wjcls)
            this.secondForm.xmcls = parseInt(this.secondForm.xmcls)
          }

          this.queryParams.groupId = this.secondForm.groupId;
          saveMetaData(this.secondForm).then(response => {
            this.$modal.msgSuccess("保存成功");
            this.isNameDisabled = true;
            this.isDisabledRule = false; // 选择元数据方案后才可以操作档号规则
            //主要实现点击档案树   元方案数据回显功能
            // console.log(this.deptOptions)

            return;
            for (var j = 0; j < this.deptOptions[0].children.length; j++) {
              console.log(this.deptOptions[0].children[j].id, j)
              if (this.deptOptions[0].children[j].id === this.secondForm.id) {
                this.deptOptions[0].children[j].groupId = this.secondForm.groupId
              }
            }
          });
        } else {
          console.log('error submit!!');
          return false;
        }
      })
    },
    // 元数据方案下拉框选中事件
    changeSelectTap(data) {
      var dataRow = this.nameOption.filter((item) => {
        return item.value == data
      })
      this.secondForm.name = dataRow[0].label;
      this.secondForm.groupId = dataRow[0].value;
      this.secondForm.type = dataRow[0].type;
    },
    // 获取信息渲染元数据方案信息标签页
    getSecondList() {
      this.resetSecond();
      console.log(this.queryParams.groupId !== undefined && this.queryParams.groupId !== null)
      if (this.queryParams.groupId !== undefined && this.queryParams.groupId !== null) {
        getMetaData(this.queryParams.groupId).then(response => {
          console.log(response, "111111111111111111111111")
          this.secondForm.name = response.data.name
          this.secondForm.groupId = response.data.id;
          this.secondForm.name = response.data.name;
          this.secondForm.type = response.data.type;
          this.isNameDisabled = true
          if (this.metaType === '0') {
            this.secondForm.wjcls = response.data.wjColLength
          } else if (this.metaType === '1') {
            this.secondForm.ajcls = response.data.ajColLength
            this.secondForm.wjcls = response.data.wjColLength
          } else {
            this.secondForm.xmcls = response.data.xmColLength
            this.secondForm.ajcls = response.data.ajColLength
            this.secondForm.wjcls = response.data.wjColLength
          }
        })
      } else {
        this.isNameDisabled = false
        this.fetchData();
      }
    },
    // 档号定义多选框选中数据
    handleSelectionChangeThird(selection) {
      this.ids = selection.map(item => item.id)
      this.names = selection.map(item => item.name)
      this.single = selection.length != 1
      this.multiple = !selection.length
    },
    // 获取档号定义列表
    getThirdList() {
      this.operate = ""
      this.loading = true;
      this.form = {
        categoryModelId: this.queryParams.id
      }
      getCodeRule(this.form).then(response => {
        this.roleList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    resetRoleForm() {
      this.roleForm = {
        id: undefined,
        name: undefined,
        starttime: undefined,
        endtime: undefined,
        categoryModelId: undefined,
        creator: undefined,
        CREATETIME: undefined,
        isMoren: null
      }
    },
    // 档号定义---新增规则
    roleHandleAdd() {
      this.resetRoleForm()
      var that = this;
      getInfo().then(res => {
        const date = new Date()
        const year = date.getFullYear()
        const month = ('0' + (date.getMonth() + 1)).slice(-2)
        const day = ('0' + date.getDate()).slice(-2)
        console.log(res.user.nickName)
        this.roleForm.CREATETIME = year + "" + month + "" + day
        console.log(res.user)
        this.roleForm.creator = res.user.nickName;
        this.roleForm.isMoren = 0
        this.$nextTick(() => {
          that.roleOpen = true;
          that.roleTitle = "新增档案规则信息";
        })
      })
      console.log(this.roleForm)
    },
    // 档号定义---修改规则
    roleHandleUpdate(row) {
      if (this.single == false) {
        this.resetThird();
        const roleId = row.id || this.ids
        this.form = {
          id: roleId.toString()
        }
        getCodeRule(this.form).then(response => {
          console.log(response.rows[0])
          this.roleForm = response.rows[0]
          if (response.rows[0].isMoren === null) {
            this.roleForm.isMoren = Number("0")
          } else {
            this.roleForm.isMoren = Number(response.rows[0].isMoren)
          }
          const dateString = response.rows[0].createTime;
          const date = new Date(dateString);
          // 获取年、月、日
          const year = date.getFullYear();
          const month = (date.getMonth() + 1).toString().padStart(2, '0');
          const day = date.getDate().toString().padStart(2, '0');
          // 拼接为新的日期字符串
          this.roleForm.CREATETIME = year + month + day;
          this.roleForm.starttime = response.rows[0].starttime.toString()
          this.roleForm.endtime = response.rows[0].endtime.toString()
          this.roleOpen = true;
          this.roleTitle = "修改档案规则信息";
        });
      } else {
        this.$message({ message: '请选择一条数据进行修改', type: 'warning' })
      }
    },
    // 档号定义规则添加提交
    submitRoleForm() {
      this.$refs["roleForm"].validate((valid) => {
        if (valid) {
          if (this.roleForm.endtime < this.roleForm.starttime) {
            this.$modal.msgWarning('开始时间不能大于结束时间')
            return;
          }
          if (this.roleForm.id != undefined) {
            updateCodeRule(this.roleForm).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.roleOpen = false;
              this.getThirdList();
            });
          } else {
            this.roleForm.categoryModelId = this.queryParams.id
            this.roleForm.starttime = Number(this.roleForm.starttime)
            this.roleForm.endtime = Number(this.roleForm.endtime)
            // if(this.roleForm.isMoren === null){
            //   this.roleForm.isMoren = "0"
            // }
            // console.log(this.roleForm)
            addCodeRule(this.roleForm).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.roleOpen = false;
              this.getThirdList();
              console.log(2222222222222222222222222)
            });
            console.log(11111111111111111)
            this.resetThird();
          }
        }
      })
    },
    // 档号定义---删除规则
    roleHandleDelete(row) {
      const roleId = row.id || this.ids
      const name = this.names
      if (roleId.length !== 0) {
        this.$modal.confirm('是否确认删除规则名称为"' + name + '"的数据项？').then(function () {
          return delCodeRole(roleId);
        }).then(() => {
          this.getThirdList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {
        });
      } else {
        this.$modal.msgError("请选择要删除的数据");
      }
    },
    //获取规则字段位数
    handleCountInput() {
      const count = this.digit - 1
      this.dropdowns = [];
      for (var i = 0; i < count; i++) {
        this.dropdowns.push({})
      }
      this.fetchRole()
    },
    handleValueChange() {
      const count = this.digit - 1
      this.dropdowns = [];
      for (var i = 0; i < count; i++) {
        this.dropdowns.push({})
      }
      this.fetchRole()
      this.ziduanStart = []
      this.ziduanEnd = ""
      this.fuhaoarr = []
      this.detailForm.bulingarr = ""
    },
    // 档号定义---新增规则明细
    detailHandleAdd(row) {
      this.resetRoleDetail()
      this.detailOpen = true
      this.roleRowId = row.id
      this.operate = "add"
      this.getSortData()
      this.dataChecked = []
    },
    // 档号定义---修改规则明细
    detailHandleUpdate(row) {
      this.dataChecked = []
      this.getSortData()
      this.resetRoleDetail()
      this.operate = "update"
      this.roleRowId = row.id
      const id = row.id || this.ids
      const type = ""
      if (this.metaType == '0') {
        this.type = "f"
      } else if (this.metaType == '1' || this.metaType == '3') {
        this.type = "v"
      }
      roleDetailList(this.type, id).then(response => {
        console.log(response.data)
        this.detailForm.categoryId = this.queryParams.id
        this.detailForm.id = this.roleRowId
        this.detailForm.columnname = response.data.columnname
        this.digit = response.data.bulingarr.length
        this.detailForm.bulingarr = response.data.bulingarr[response.data.bulingarr.length - 1]
        for (var i = 0; i < response.data.ziduanarr.length - 1; i++) {
          this.ziduanStart[i] = response.data.ziduanarr[i]
        }
        for (var i = 0; i < response.data.fuhaoarr.length; i++) {
          this.fuhaoarr[i] = response.data.fuhaoarr[i]
        }
        this.ziduanEnd = response.data.ziduanarr[response.data.ziduanarr.length - 1]
        if (response.data.order != null && response.data.order != undefined && response.data.order != '') {
          var arr = response.data.order.split(',')
          const result = arr.reduce((acc, item) => {
            const [key, value] = item.trim().split(" ");
            acc[key] = value;
            return acc;
          }, {});
          for (let i = 0; i < arr.length; i++) {
            if (this.sortData.filter((item) => item.fieldName === Object.keys(result)[i]).length != 0) {
              // const index = this.sortData.findIndex((item) => item.fieldName === Object.keys(result)[i])
              const data = this.sortData.filter((item) => item.fieldName === Object.keys(result)[i])
              data[0].isOrder = Object.values(result)[i]
              this.dataChecked = this.dataChecked.concat(data)
            }
          }
        }
        this.detailForm.jianbuling = response.data.jianbuling
        this.detailForm.jiancunchuziduan = response.data.jiancunchuziduan
        this.detailForm.jianlianjie = response.data.jianlianjie
        this.detailForm.jianziduan = response.data.jianziduan
        // console.log(this.dataChecked)
        this.restoreForm.categoryId = this.queryParams.id
        this.restoreForm.id = this.roleRowId
        this.restoreForm.columnname = response.data.columnname
        this.restoreForm.bulingarr = response.data.bulingarr[response.data.bulingarr.length - 1]
        // this.restoreForm.ziduanStart = response.data.ziduanarr
        // this.restoreForm.fuhaoarr = response.data.fuhaoarr
        this.restoreForm.ziduanStart = []
        this.restoreForm.fuhaoarr = []
        for (var i = 0; i < response.data.ziduanarr.length; i++) {
          this.restoreForm.ziduanStart[i] = response.data.ziduanarr[i]
        }
        for (var i = 0; i < response.data.fuhaoarr.length; i++) {
          this.restoreForm.fuhaoarr[i] = response.data.fuhaoarr[i]
        }
        this.restoreForm.ziduanEnd = response.data.ziduanarr[response.data.ziduanarr.length - 1]
        this.restoreForm.digit = response.data.bulingarr.length
        this.restoreForm.jianbuling = response.data.jianbuling
        this.restoreForm.jiancunchuziduan = response.data.jiancunchuziduan
        this.restoreForm.jianlianjie = response.data.jianlianjie
        this.restoreForm.jianziduan = response.data.jianziduan
        this.restoreForm.dataChecked = this.dataChecked
        this.detailOpen = true
      });
    },
    // 档号定义---规则明细保存
    submitDetail() {

      this.$refs["detailForm"].validate((valid) => {

        if (valid) {
          if (this.detailForm.id != undefined) {
            this.submit()
            if (this.flag == true) {
              this.detailForm.categoryId = this.queryParams.id
              this.detailForm.id = this.roleRowId
              this.detailForm.fuhaoarr = this.fuhaoarr
              if (this.digit != this.ziduanStart.length) {
                this.ziduanStart.push(this.ziduanEnd)
              }
              // this.ziduanStart.push(this.ziduanEnd)
              this.detailForm.ziduanarr = this.ziduanStart
              var arr = []
              if (this.detailForm.bulingarr == "") {
                for (let i = 0; i < this.detailForm.ziduanarr.length; i++) {
                  arr.push("0");
                }
              } else {
                for (let i = 0; i < this.fuhaoarr.length; i++) {
                  arr.push("0");
                }
                arr.push(this.detailForm.bulingarr)
              }
              // this.detailForm.bulingarr = arr
              this.detailForm.type = this.metaType
              this.detailForm.jianbuling = this.detailForm.jianbuling
              var data = {
                bulingarr: arr,
                ziduanarr: this.detailForm.ziduanarr,
                fuhaoarr: this.detailForm.fuhaoarr,
                columnname: this.detailForm.columnname,
                jiancunchuziduan: this.detailForm.jiancunchuziduan,
                jianlianjie: this.detailForm.jianlianjie,
                jianziduan: this.detailForm.jianziduan,
                jianbuling: this.detailForm.jianbuling,
                filelianjie: this.detailForm.filelianjie,
                order: this.detailForm.order,
                categoryId: this.detailForm.categoryId,
                type: this.detailForm.type,
                id: this.detailForm.id,
              }
              console.log(this.detailForm, data)
              updateRoleDetail(data).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.detailOpen = false;
                this.sortOpen = false;
                this.getThirdList();
              });
            }
          } else {
            this.submit()
            if (this.flag == true) {
              this.detailForm.categoryId = this.queryParams.id
              this.detailForm.id = this.roleRowId
              this.detailForm.fuhaoarr = this.fuhaoarr
              this.ziduanStart.push(this.ziduanEnd)
              this.detailForm.ziduanarr = this.ziduanStart
              var arr = []
              if (this.detailForm.bulingarr == "") {
                for (let i = 0; i < this.detailForm.ziduanarr.length; i++) {
                  arr.push("0");
                }
              } else {
                for (let i = 0; i < this.fuhaoarr.length; i++) {
                  arr.push("0");
                }
                arr.push(this.detailForm.bulingarr)
              }
              // this.detailForm.bulingarr = arr
              this.detailForm.type = this.metaType
              var data = {
                bulingarr: arr,
                ziduanarr: this.detailForm.ziduanarr,
                fuhaoarr: this.detailForm.fuhaoarr,
                columnname: this.detailForm.columnname,
                jiancunchuziduan: this.detailForm.jiancunchuziduan,
                jianlianjie: this.detailForm.jianlianjie,
                jianziduan: this.detailForm.jianziduan,
                jianbuling: this.detailForm.jianbuling,
                filelianjie: this.detailForm.filelianjie,
                order: this.detailForm.order,
                categoryId: this.detailForm.categoryId,
                type: this.detailForm.type,
                id: this.detailForm.id,
              }
              console.log(this.detailForm, data)
              addRoleDetail(data).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.detailOpen = false;
                this.sortOpen = false;
                this.getThirdList();
              });
            }
          }
        }
      })
    },
    //校验规则档号明细页面输入
    submit() {
      if (this.detailForm.columnname == undefined) {
        this.$message({ message: '请选择档号存储字段!', type: 'warning' })
        this.flag = false
        return;
      }
      if (this.digit == "" || this.digit == '0' || this.digit == undefined || Number(this.digit) <= 0) {
        this.$message({ message: '规则字段位数需要大于0!', type: 'warning' })
        this.flag = false
        return;
      } else {
        for (var i = 0; i < parseInt(this.digit) - 1; i++) {
          if (this.ziduanStart[i] == undefined) {
            this.$message({ message: '请输入第' + (i + 1) + '位组成字段!', type: 'warning' })
            this.flag = false
            return;
          }
          if (this.fuhaoarr[i] == undefined) {
            this.$message({ message: '请输入第' + (i + 1) + '个组成符号!', type: 'warning' })
            this.flag = false
            return;
          }
        }
      }
      if (this.ziduanEnd == undefined || this.ziduanEnd == "") {
        this.$message({ message: '请输入第' + parseInt(this.digit) + '位组成字段!', type: 'warning' })
        this.flag = false
        return;
      }
      if (this.metaType == '1' || this.metaType == '3') {
        if (this.detailForm.jiancunchuziduan == "") {
          this.$message({ message: '请输入卷内文件层档号!', type: 'warning' })
          this.flag = false
          return;
        }
        if (this.detailForm.jianlianjie == "") {
          this.$message({ message: '请输入卷内文件层连接符号!', type: 'warning' })
          this.flag = false
          return;
        }
        if (this.detailForm.jianziduan == "") {
          this.$message({ message: '请输入卷内文件层件字段!', type: 'warning' })
          this.flag = false

        }
      }
    },
    // 档号定义---获取下拉框
    fetchRole() {
      if (this.metaType != '' && this.queryParams.groupId != null) {
        // 获取档号字段下拉框
        var type = ""
        if (this.metaType == '0') {
          // 组件
          type = this.metaType
        } else {
          // 项目没有档号 所以下拉框取得是卷
          type = '1'
        }
        this.form = {
          isArchiveNo: '1',
          type: type,
          groupId: this.queryParams.groupId
        }
        metaList(this.form).then(response => {
          this.colOption = response.data.map(option => {
            return {
              id: option.id,
              value: option.fieldName,
              label: option.fieldCaption
            }
          })
        })

        // 获取档号连接字段下拉框
        this.form1 = {
          isArchiveNo: '0',
          type: type,
          groupId: this.queryParams.groupId
        }
        // metaList(this.form1).then(response => {
        //   console.log(response,"00000")
        //   this.ziduanSOption = response.data.map(option => {
        //     return {
        //       id: option.id,
        //       value: option.fieldName,
        //       label: option.fieldCaption
        //     }
        //   })
        // })
        listforshy2({
          groupId: this.queryParams.groupId,
          type: type,
          cateogryId: this.queryParams.categoryId,
          pageNum: 1,
          pageSize: 20000
        }).then(response => {
          var dataArr = response.rows.filter(res => { return res.HAD == 1 })
          this.ziduanSOption = dataArr.map(option => {
            return {
              id: option.ID,
              value: option.FIELD_NAME,
              label: option.FIELD_CAPTION

            }


          })
        })
        // 获取档号最后一段字段下拉框
        this.form2 = {
          isArchiveNo: '0',
          fieldType: '1',
          type: type,
          groupId: this.queryParams.groupId
        }
        metaList(this.form2).then(response => {
          this.ziduanEOption = response.data.map(option => {
            return {
              id: option.id,
              value: option.fieldName,
              label: option.fieldCaption
            }
          })
        })
        // 获取卷内文件层档号字段下拉框
        this.form3 = {
          isArchiveNo: '1',
          type: '0',
          groupId: this.queryParams.groupId
        }
        metaList(this.form3).then(response => {
          this.jianziduanOption = response.data.map(option => {
            return {
              id: option.id,
              value: option.fieldName,
              label: option.fieldCaption
            }
          })
        })
        //获取卷内文件层档号最后一位字段下拉框
        this.form4 = {
          isArchiveNo: '0',
          fieldType: '1',
          type: '0',
          groupId: this.queryParams.groupId
        }
        metaList(this.form4).then(response => {
          this.jianOption = response.data.map(option => {
            return {
              id: option.id,
              value: option.fieldName,
              label: option.fieldCaption
            }
          })
        })
      }
    },
    // 排序
    detailSort() {
      this.detailOpen = false
      this.sortOpen = true;
      console.log(this.dataChecked, "__________________________________")

    },
    // 排序数据
    getSortData() {
      var type = ""
      if (this.metaType == '0') {
        type = this.metaType
      } else {
        type = '1'
      }
      this.form = {
        type: type,
        groupId: this.queryParams.groupId
      }
      metaList(this.form).then(response => {
        this.sortData = response.data.map((item, index) => ({
          fieldCaption: item.fieldCaption,
          fieldName: item.fieldName,
          isOrder: 'asc',
          key: index
        }));
      })
    },
    // 定义
    detail() {
      this.detailOpen = true
    },
    determine(value, isOrder) {
      var arr1 = []
      console.log(value, isOrder)
      for (var i = 0; i < isOrder.length; i++) {
        for (var j = 0; j < value.length; j++) {
          if (isOrder[i].key == value[j]) {
            const str = isOrder[i].code + "$" + isOrder[i].isOrder
            arr1.push(str)
          }
        }
      }
      this.detailForm.order = arr1.toString()
      console.log(this.detailForm.order)
      this.submitDetail()
    },
    // 排序恢复默认值
    sortRestore(row) {
      if (this.operate == "add") {
        this.resetRoleDetail();
      } else {
        this.resetRoleDetail();
        this.detailForm.categoryId = this.restoreForm.categoryId
        this.detailForm.id = this.restoreForm.id
        this.detailForm.columnname = this.restoreForm.columnname
        this.detailForm.jianbuling = this.restoreForm.jianbuling
        this.detailForm.jiancunchuziduan = this.restoreForm.jiancunchuziduan
        this.detailForm.jianlianjie = this.restoreForm.jianlianjie
        this.detailForm.jianziduan = this.restoreForm.jianziduan
        this.detailForm.bulingarr = this.restoreForm.bulingarr
        this.digit = this.restoreForm.digit
        for (var i = 0; i < this.restoreForm.ziduanStart.length; i++) {
          this.ziduanStart[i] = this.restoreForm.ziduanStart[i]
        }
        for (var i = 0; i < this.restoreForm.fuhaoarr.length; i++) {
          this.fuhaoarr[i] = this.restoreForm.fuhaoarr[i]
        }
        this.ziduanEnd = this.restoreForm.ziduanStart[this.restoreForm.ziduanStart.length - 1]
        this.dataChecked = this.restoreForm.dataChecked
      }
    },
    //搜索按钮操作
    handleQuery() {
      this.queryParam.pageNum = 1;
      this.getApplyList();
    },
    //应用定义重置按钮
    resetQuery() {
      this.resetForm("queryForm");
      this.getApplyList();
    },
    //应用模块新增取消
    applyCancel() {
      this.applyOpen = false
    },
    //应用定义新增模块
    applyHandleAdd() {
      this.applyOpen = true
    },
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.MENU_ID)
      this.applySingle = selection.length != 1
      this.applyMultiple = !selection.length
      this.applyName = selection.map(item => item.MENU_NAME)
    },
    //应用定义删除模块
    applyHandleDelete(row) {
      // if (this.applySingle == false) {
      //   const applyId = row.MENU_ID || this.ids
      //   const categoryId = this.queryParams.id
      //   const applyName = this.applyName
      //   this.$modal.confirm('是否确认删除应用模块菜单名称为"' + applyName + '"的数据项？').then(function () {
      //     return delApply(categoryId, applyId);
      //   }).then(() => {
      //     this.getApplyList();
      //     this.$modal.msgSuccess("删除成功");
      //   }).catch(() => {
      //   });
      // } else {
      //   this.$message({ message: '请选择一条数据进行删除', type: 'warning' })
      // }
      var that = this;
      if (this.applyMultiple == false) {
        const categoryId = this.queryParams.id
        this.$modal.confirm("是否确认删除应用模块菜单所选的数据项？").then(function () {
          delArrApply({
            categoryId: categoryId,
            menuIds: that.ids
          }).then(res => {
            that.getApplyList();
            that.$modal.msgSuccess("删除成功");
          }).catch(() => {

          })
        })
      } else {
        this.$message({ message: '请选择条数据进行删除', type: 'warning' })
      }
    },
    // 复制到
    applyHandleCopy() {
      if (this.applySingle == false) {
        this.getApplyFZList();
        this.applyCopyOpen = true
      } else {
        this.$message({ message: '请选择一条数据进行复制', type: 'warning' })
      }
    },
    // 复制到取消
    applyCopyCancel() {
      this.applyCopyOpen = false
    },
    // 复制到弹窗保存
    submitCopyApply(row) {
      const clonedmenuId = row.MENU_ID || this.ids
      const clonetomenuIds = this.applyCopyForm.menuName
      const categoryId = this.queryParams.id
      if (clonetomenuIds.length > 0) {
        this.form = {
          clonedmenuId: clonedmenuId.toString(),
          clonetomenuIds: clonetomenuIds,
          categoryId: categoryId
        }
        console.log(this.form)
        copyApply(this.form).then(response => {
          this.$modal.msgSuccess("复制成功");
          this.resetForm("applyCopyForm");
          this.applyCopyOpen = false;
          this.getApplyList();
        });
      } else {
        this.$message({ message: '请选择至少一个模块', type: 'warning' })
      }
    },
    //应用定义穿梭框
    getApplyTrans() {
      // console.log(this.metaType)
      if (this.metaType == 0) {
        this.IsDzwjDetail = true
        this.IsJianDetail = false
        this.IsJuanDetail = false
        this.IsXmDetail = false
      } else if (this.metaType == 1) {
        this.IsJianDetail = true
        this.IsDzwjDetail = true
        this.IsJuanDetail = false
        this.IsXmDetail = false
      } else if (this.metaType == 3) {
        this.IsJuanDetail = true
        this.IsJianDetail = true
        this.IsDzwjDetail = true
        this.IsXmDetail = false
      }
    },

    enableTap(row, enableOperate) {
      var that = this;
      that.ApplyDetailData = [];
      this.myDataChecked = [];
      this.enableOperate = enableOperate;
      this.menuID = row.MENU_ID
      this.applyDetailOpen = true
      if (enableOperate == 'data') {
        this.isShowOrder = true
      } else {
        this.isShowOrder = false
      }
      this.getApplyTrans()
      var field = ""
      if (enableOperate == "show") {
        if (this.metaType == 0) {
          field = "jianlistfield"
        } else if (this.metaType == 1) {
          field = "juanlistfield"
        } else if (this.metaType == 3) {
          field = "xiangmulistfield"
        }
      } else if (enableOperate == 'query') {
        if (this.metaType == 0) {
          field = "jianquery"
        } else if (this.metaType == 1) {
          field = "juanquery"
        } else if (this.metaType == 3) {
          field = "xiangmuquery"
        }
      } else if (enableOperate == 'data') {
        if (this.metaType == 0) {
          field = "jianorder"
        } else if (this.metaType == 1) {
          field = "juanorder"
        } else if (this.metaType == 3) {
          field = "xiangmuorder"
        }
      } else {
        if (this.metaType == 0) {
          field = "jian" + enableOperate + "field";
        } else if (this.metaType == 1) {
          field = "juan" + enableOperate + "field";
        } else if (this.metaType == 3) {
          field = "xiangmu" + enableOperate + "field";
        }
      }


      this.form = {
        type: this.metaType,
        categoryId: this.queryParams.id,
        field: field,
        menuId: this.menuID
      }

      getmdatalist(this.form).then(response => {

        this.applyDetailData = response.data.map((item, index) => {
          return {
            fieldCaption: item.FIELD_CAPTION,
            fieldName: item.FIELD_NAME,
            isOrder: 'asc',
            key: index
          }
        })
        this.form = {
          menuId: this.menuID,
          categoryId: this.queryParams.id,
          field: field
        }

        this.getApplyXinxi(this.form, this.enableOperate)
      })



    },

    // 获取应用定义启用信息
    getApplyXinxi(form, enableOperate) {
      fieldlist(form).then(response => {
        console.log(response,this.applyDetailData,"11111111111111111")
        if (response.data.field != null && response.data.field != "" && response.data.field != undefined) {
          if (enableOperate == 'data') {
            var arr = response.data.field.split(',')

            const result = arr.reduce((acc, item) => {
              const [key, value] = item.trim().split("$");
              acc[key] = value;
              return acc;
            }, {});
            console.log(arr, result,arr.length)
            for (let i = 0; i < arr.length; i++) {
                // console.log(arr[i],"3333333333")

                // let res = this.applyDetailData.filter((item) => {
                //   console.log(item.fieldName == Object.keys(result)[i],item.fieldName , Object.keys(result)[i])
                //   return  item.fieldName == Object.keys(result)[i]
                // });
                // console.log(res,"dsafjklsafjksdfjklsdafjk")
              if (this.applyDetailData.filter((item) => item.fieldName == Object.keys(result)[i]) !== []) {
                const data = this.applyDetailData.filter((item) => item.fieldName == Object.keys(result)[i])
                console.log(data,"skldfjksdlfjkl")
                data[0].isOrder = Object.values(result)[i]
                this.myDataChecked = this.myDataChecked.concat(data)
              }
            }
          } else {
            var arr = response.data.field.split(',')
            for (let i = 0; i < arr.length; i++) {
              const data = this.applyDetailData.filter((item) => item.fieldName === arr[i])
              this.myDataChecked = this.myDataChecked.concat(data)
            }
          }
        }
        this.ApplyDetailData = this.applyDetailData
      })
    },
    // 点击项目明细按钮
    XmDetail() {
      this.myDataChecked = []
      this.applyDetailOpen = true
      this.IsXmDetail = false
      this.IsJuanDetail = true
      this.IsJianDetail = true
      this.IsDzwjDetail = true
      // 各个展示的按钮
      var field = ""
      if (this.enableOperate == 'show') {
        field = "xiangmulistfield"
      } else if (this.enableOperate == 'add') {
        field = "xiangmuaddfield"
      } else if (this.enableOperate == 'update') {
        field = "xiangmuupdatefield"
      } else if (this.enableOperate == 'export') {
        field = "xiangmuexportfield"
      } else if (this.enableOperate == 'query') {
        field = "xiangmuquery"
      } else if (this.enableOperate == 'data') {
        field = "xiangmuorder"
      }
      this.form = {
        type: 3,
        categoryId: this.queryParams.id,
        field: field,
        menuId: this.menuID
      }
      getmdatalist(this.form).then(response => {
        this.applyDetailData = response.data.map((item, index) => {
          return {
            fieldCaption: item.FIELD_CAPTION,
            fieldName: item.FIELD_NAME,
            isOrder: 'asc',
            key: index
          }
        })
        this.form = {
          menuId: this.menuID,
          categoryId: this.queryParams.id,
          field: field
        }
        this.getApplyXinxi(this.form, this.enableOperate)
      })
    },
    // 点击卷明细按钮
    JuanDetail() {
      this.myDataChecked = []
      this.applyDetailOpen = true
      this.IsJuanDetail = false
      // 各个展示的按钮
      var field = ""
      if (this.enableOperate == 'show') {
        field = "juanlistfield"
      } else if (this.enableOperate == 'add') {
        field = "juanaddfield"
      } else if (this.enableOperate == 'update') {
        field = "juanupdatefield"
      } else if (this.enableOperate == 'export') {
        field = "juanexportfield"
      } else if (this.enableOperate == 'query') {
        field = "juanquery"
      } else if (this.enableOperate == 'data') {
        field = "juanorder"
      }
      this.form = {
        type: 1,
        categoryId: this.queryParams.id,
        field: field,
        menuId: this.menuID
      }
      getmdatalist(this.form).then(response => {
        this.applyDetailData = response.data.map((item, index) => {
          return {
            fieldCaption: item.FIELD_CAPTION,
            fieldName: item.FIELD_NAME,
            isOrder: 'asc',
            key: index
          }
        })
        this.form = {
          menuId: this.menuID,
          categoryId: this.queryParams.id,
          field: field
        }
        this.getApplyXinxi(this.form, this.enableOperate)
      })
      if (this.metaType == 1) { //卷
        this.IsJianDetail = true
        this.IsDzwjDetail = true
      } else if (this.metaType == 3) { //项目
        this.IsJianDetail = true
        this.IsDzwjDetail = true
        this.IsXmDetail = true
      }
    },
    // 点击件明细
    JianDetail() {
      this.myDataChecked = []
      this.applyDetailOpen = true
      this.IsJianDetail = false
      // 各个展示的按钮
      var field = ""
      if (this.enableOperate == 'show') {
        field = "jianlistfield"
      } else if (this.enableOperate == 'add') {
        field = "jianaddfield"
      } else if (this.enableOperate == 'update') {
        field = "jianupdatefield"
      } else if (this.enableOperate == 'export') {
        field = "jianexportfield"
      } else if (this.enableOperate == 'query') {
        field = "jianquery"
      } else if (this.enableOperate == 'data') {
        field = "jianorder"
      }
      this.form = {
        type: 0,
        categoryId: this.queryParams.id,
        field: field,
        menuId: this.menuID
      }
      getmdatalist(this.form).then(response => {
        this.applyDetailData = response.data.map((item, index) => {
          return {
            fieldCaption: item.FIELD_CAPTION,
            fieldName: item.FIELD_NAME,
            isOrder: 'asc',
            key: index
          }
        })
        this.form = {
          menuId: this.menuID,
          categoryId: this.queryParams.id,
          field: field
        }
        this.getApplyXinxi(this.form, this.enableOperate)
      })
      if (this.metaType == 1) { // 卷
        this.IsJuanDetail = true
        this.IsDzwjDetail = true
      } else if (this.metaType == 3) { //项目
        this.IsJuanDetail = true
        this.IsDzwjDetail = true
        this.IsXmDetail = true
      } else if (this.metaType == 0) { //件
        this.IsDzwjDetail = true
      }
    },
    // 点击电子文件明细
    DzwjDetail() {
      this.myDataChecked = []
      console.log('电子文件, 操作:', this.enableOperate)
      this.applyDetailOpen = true
      this.IsDzwjDetail = false
      // 各个展示的按钮
      var field = ""
      if (this.enableOperate == 'show') {
        field = "efilelistfield"
      } else if (this.enableOperate == 'add') {
        field = "efileaddfield"
      } else if (this.enableOperate == 'update') {
        field = "efileupdatefield"
      } else if (this.enableOperate == 'export') {
        field = "efileexportfield"
      } else if (this.enableOperate == 'query') {
        field = "efilequery"
      } else if (this.enableOperate == 'data') {
        field = "efileorder"
      }
      this.form = {
        type: 2,
        categoryId: this.queryParams.id,
        field: field,
        menuId: this.menuID
      }
      getmdatalist(this.form).then(response => {
        this.applyDetailData = response.data.map((item, index) => {
          return {
            fieldCaption: item.FIELD_CAPTION,
            fieldName: item.FIELD_NAME,
            isOrder: 'asc',
            key: index
          }
        })
        this.form = {
          menuId: this.menuID,
          categoryId: this.queryParams.id,
          field: field
        }
        this.getApplyXinxi(this.form, this.enableOperate)
        console.log(this.applyDetailData, "dianziwenjianc")
      })
      if (this.metaType == 1) { // 卷
        this.IsJuanDetail = true
        this.IsJianDetail = true
      } else if (this.metaType == 3) { //项目
        this.IsJuanDetail = true
        this.IsJianDetail = true
        this.IsXmDetail = true
      } else if (this.metaType == 0) { //件
        this.IsJianDetail = true
      }
    },
    // 保存应用明细
    submitApplyDetail(value, isOrder, biaoshi) {
      this.ProcessData(value, isOrder, this.enableOperate, this.menuID)
      console.log('form表单:', this.form)
      console.log(biaoshi)
      if (biaoshi == false) {
        addApplyDetail(this.form).then(response => {
          // this.applyDetailOpen = false;
          // this.getApplyList();
          // this.enableOperate = ''
        })
      } else {
        addApplyDetail(this.form).then(response => {
          this.applyDetailOpen = false;
          this.getApplyList();
          this.enableOperate = ''
          this.myDataChecked = []
          this.ApplyDetailData = []
        })
      }
    },
    ProcessData(value, isOrder, enableOperate, menuID) {
      console.log('操作', enableOperate)
      console.log(value, '-----------', isOrder)
      console.log('件:', this.IsJianDetail, ',卷:', this.IsJuanDetail, ',项目:', this.IsXmDetail, ',电子文件:', this.IsDzwjDetail)
      this.form = {
        menuId: menuID,
        categoryId: this.queryParams.id
      }
      // 列表展示
      if (this.enableOperate == 'show') {
        if (this.IsJianDetail == false) {
          var arr = []
          for (var j = 0; j < value.length; j++) {
            for (var i = 0; i < isOrder.length; i++) {
              if (isOrder[i].key == value[j]) {
                const str = isOrder[i].code
                arr.push(str)
              }
            }
          }
          this.form.jianlistfield = arr.map(field => field.replace(/'/g, "")).toString() // 件展示字段
        } else if (this.IsDzwjDetail == false) {
          var arr = []
          for (var j = 0; j < value.length; j++) {
            for (var i = 0; i < isOrder.length; i++) {
              if (isOrder[i].key == value[j]) {
                const str = isOrder[i].code
                arr.push(str)
              }
            }
          }
          this.form.efilelistfield = arr.map(field => field.replace(/'/g, "")).toString() // 电子文件展示字段
        } else if (this.IsJuanDetail == false) {
          var arr = []
          for (var j = 0; j < value.length; j++) {
            for (var i = 0; i < isOrder.length; i++) {
              if (isOrder[i].key == value[j]) {
                console.log(value[j], "=====", isOrder[i])
                const str = isOrder[i].code
                arr.push(str)
              }
            }
          }
          this.form.juanlistfield = arr.map(field => field.replace(/'/g, "")).toString() // 卷展示字段
        } else if (this.IsXmDetail == false) {
          var arr = []
          for (var j = 0; j < value.length; j++) {
            for (var i = 0; i < isOrder.length; i++) {
              if (isOrder[i].key == value[j]) {
                const str = isOrder[i].code
                arr.push(str)
              }
            }
          }
          this.form.xiangmulistfield = arr.map(field => field.replace(/'/g, "")).toString() // 项目字段
        }
      }
      // 添加展示
      else if (this.enableOperate == 'add') {
        if (this.IsJianDetail == false) {
          var arr = []
          for (var j = 0; j < value.length; j++) {
            for (var i = 0; i < isOrder.length; i++) {
              if (isOrder[i].key == value[j]) {
                const str = isOrder[i].code
                arr.push(str)
              }
            }
          }
          this.form.jianaddfield = arr.map(field => field.replace(/'/g, "")).toString() // 件添加字段
        } else if (this.IsDzwjDetail == false) {
          var arr = []
          for (var j = 0; j < value.length; j++) {
            for (var i = 0; i < isOrder.length; i++) {
              if (isOrder[i].key == value[j]) {
                const str = isOrder[i].code
                arr.push(str)
              }
            }
          }
          this.form.efileaddfield = arr.map(field => field.replace(/'/g, "")).toString()  // 电子文件添加字段
        } else if (this.IsJuanDetail == false) {
          var arr = [] // 卷字段
          for (var j = 0; j < value.length; j++) {
            for (var i = 0; i < isOrder.length; i++) {
              if (isOrder[i].key == value[j]) {
                const str = isOrder[i].code
                arr.push(str)
              }
            }
          }
          this.form.juanaddfield = arr.map(field => field.replace(/'/g, "")).toString()  // 卷添加字段
        } else if (this.IsXmDetail == false) {
          var arr = []
          for (var j = 0; j < value.length; j++) {
            for (var i = 0; i < isOrder.length; i++) {
              if (isOrder[i].key == value[j]) {
                const str = isOrder[i].code
                arr.push(str)
              }
            }
          }
          this.form.xiangmuaddfield = arr.map(field => field.replace(/'/g, "")).toString() // 项目添加字段
        }
      }
      // 修改展示
      else if (this.enableOperate == 'update') {
        if (this.IsJianDetail == false) {
          var arr = []
          for (var j = 0; j < value.length; j++) {
            for (var i = 0; i < isOrder.length; i++) {
              if (isOrder[i].key == value[j]) {
                const str = isOrder[i].code
                arr.push(str)
              }
            }
          }
          this.form.jianupdatefield = arr.map(field => field.replace(/'/g, "")).toString() // 件修改字段
        } else if (this.IsDzwjDetail == false) {
          var arr = []
          for (var j = 0; j < value.length; j++) {
            for (var i = 0; i < isOrder.length; i++) {
              if (isOrder[i].key == value[j]) {
                const str = isOrder[i].code
                arr.push(str)
              }
            }
          }
          this.form.efileupdatefield = arr.map(field => field.replace(/'/g, "")).toString()  // 电子文件修改字段
        } else if (this.IsJuanDetail == false) {
          var arr = [] // 卷字段
          for (var j = 0; j < value.length; j++) {
            for (var i = 0; i < isOrder.length; i++) {
              if (isOrder[i].key == value[j]) {
                const str = isOrder[i].code
                arr.push(str)
              }
            }
          }
          this.form.juanupdatefield = arr.map(field => field.replace(/'/g, "")).toString()  // 卷修改字段
        } else if (this.IsXmDetail == false) {
          var arr = []
          for (var j = 0; j < value.length; j++) {
            for (var i = 0; i < isOrder.length; i++) {
              if (isOrder[i].key == value[j]) {
                const str = isOrder[i].code
                arr.push(str)
              }
            }
          }
          this.form.xiangmuupdatefield = arr.map(field => field.replace(/'/g, "")).toString() // 项目修改字段
        }
      }
      // 导出展示
      else if (this.enableOperate == 'export') {
        if (this.IsJianDetail == false) {
          var arr = []
          for (var j = 0; j < value.length; j++) {
            for (var i = 0; i < isOrder.length; i++) {
              if (isOrder[i].key == value[j]) {
                const str = isOrder[i].code
                arr.push(str)
              }
            }
          }
          this.form.jianexportfield = arr.map(field => field.replace(/'/g, "")).toString() // 件导出字段
        } else if (this.IsDzwjDetail == false) {
          var arr = []
          for (var j = 0; j < value.length; j++) {
            for (var i = 0; i < isOrder.length; i++) {
              if (isOrder[i].key == value[j]) {
                const str = isOrder[i].code
                arr.push(str)
              }
            }
          }
          this.form.efileexportfield = arr.map(field => field.replace(/'/g, "")).toString()  // 电子文件导出字段
        } else if (this.IsJuanDetail == false) {
          var arr = [] // 卷字段
          for (var j = 0; j < value.length; j++) {
            for (var i = 0; i < isOrder.length; i++) {
              if (isOrder[i].key == value[j]) {
                const str = isOrder[i].code
                arr.push(str)
              }
            }
          }
          this.form.juanexportfield = arr.map(field => field.replace(/'/g, "")).toString()  // 卷导出字段
        } else if (this.IsXmDetail == false) {
          var arr = []
          for (var j = 0; j < value.length; j++) {
            for (var i = 0; i < isOrder.length; i++) {
              if (isOrder[i].key == value[j]) {
                const str = isOrder[i].code
                arr.push(str)
              }
            }
          }
          this.form.xiangmuexportfield = arr.map(field => field.replace(/'/g, "")).toString() // 项目导出字段
        }
      }
      // 查询展示
      else if (this.enableOperate == 'query') {
        if (this.IsJianDetail == false) {
          var arr = []
          for (var j = 0; j < value.length; j++) {
            for (var i = 0; i < isOrder.length; i++) {
              if (isOrder[i].key == value[j]) {
                const str = isOrder[i].code
                arr.push(str)
              }
            }
          }
          this.form.jianquery = arr.map(field => field.replace(/'/g, "")).toString() // 件查询字段
        } else if (this.IsDzwjDetail == false) {
          var arr = []
          for (var j = 0; j < value.length; j++) {
            for (var i = 0; i < isOrder.length; i++) {
              if (isOrder[i].key == value[j]) {
                const str = isOrder[i].code
                arr.push(str)
              }
            }
          }
          this.form.efilequery = arr.map(field => field.replace(/'/g, "")).toString()  // 电子文件查询字段
        } else if (this.IsJuanDetail == false) {
          var arr = [] // 卷字段
          for (var j = 0; j < value.length; j++) {
            for (var i = 0; i < isOrder.length; i++) {
              if (isOrder[i].key == value[j]) {
                const str = isOrder[i].code
                arr.push(str)
              }
            }
          }
          this.form.juanquery = arr.map(field => field.replace(/'/g, "")).toString()  // 卷查询字段
        } else if (this.IsXmDetail == false) {
          var arr = []
          for (var j = 0; j < value.length; j++) {
            for (var i = 0; i < isOrder.length; i++) {
              if (isOrder[i].key == value[j]) {
                const str = isOrder[i].code
                arr.push(str)
              }
            }
          }
          this.form.xiangmuquery = arr.map(field => field.replace(/'/g, "")).toString() // 项目查询字段
        }
      }
      // 数据展示
      else if (this.enableOperate == 'data') {
        if (this.IsJianDetail == false) {
          var arr = []
          for (var j = 0; j < value.length; j++) {
            for (var i = 0; i < isOrder.length; i++) {
              if (isOrder[i].key == value[j]) {
                const str = isOrder[i].code + "$" + isOrder[i].isOrder
                arr.push(str)
              }
            }
          }
          this.form.jianorder = arr.toString() // 件数据排序
          console.log(this.form.jianorder)
        } else if (this.IsDzwjDetail == false) {
          var arr = []
          for (var j = 0; j < value.length; j++) {
            for (var i = 0; i < isOrder.length; i++) {
              if (isOrder[i].key == value[j]) {
                const str = isOrder[i].code + "$" + isOrder[i].isOrder
                arr.push(str)
              }
            }
          }
          this.form.efileorder = arr.toString() // 电子文件数据排序
        } else if (this.IsJuanDetail == false) {
          var arr = []
          for (var j = 0; j < value.length; j++) {
            for (var i = 0; i < isOrder.length; i++) {
              if (isOrder[i].key == value[j]) {
                const str = isOrder[i].code + "$" + isOrder[i].isOrder
                arr.push(str)
              }
            }
          }
          this.form.juanorder = arr.toString()  // 卷数据排序
        } else if (this.IsXmDetail == false) {
          var arr = []
          for (var j = 0; j < value.length; j++) {
            for (var i = 0; i < isOrder.length; i++) {
              if (isOrder[i].key == value[j]) {
                const str = isOrder[i].code + "$" + isOrder[i].isOrder
                arr.push(str)
              }
            }
          }
          this.form.xiangmuorder = arr.toString() // 项目数据排序
        }
      }
    },
    // 获取菜单
    getApplyMenu() {
      listMenu(this.queryParams.id).then(response => {
        this.applyOption = response.data.map(option => {
          return {
            value: option.MENU_ID,
            label: option.MENU_NAME
          }
        })
      })
    },


    //复制到列表接口
    getApplyFZList() {

      this.queryParam.categoryId = this.queryParams.id
      getApply({
        'categoryId': this.queryParam.categoryId,
        'menuName': "null",
        'pageNum': 1,
        'pageSize': 10000
      }).then(response => {
        // console.log(response.rows,this.ids,"-------------------")
       var arrList= response.rows.filter(res=>{
          return res.MENU_ID!=this.ids[0]
        })
        this.applyOptionCopy = arrList.map(option => {
          return {
            value: option.MENU_ID,
            label: option.MENU_NAME
          }
        })
      }
      );



    },


    // 获取应用定义表格数据
    getApplyList() {
      this.loading = true;
      this.queryParam.categoryId = this.queryParams.id
      if (this.queryParam.menuName == "") {
        this.queryParam.menuName = "null"
        console.log(this.queryParam, "-----------")
        getApply(this.queryParam).then(response => {
          console.log(response, "================================")
          this.applyList = response.rows;
          this.applyTotal = response.total;
          this.loading = false;
        }
        );
        this.queryParam.menuName = ""
      } else {
        getApply(this.queryParam).then(response => {
          this.applyList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
        );
      }
    },
    submitApply() {
      if (this.applyForm.menuName.length > 0) {
        this.form = {
          menuids: this.applyForm.menuName,
          categoryId: this.queryParams.id
        }
        console.log(this.form)
        addApply(this.form).then(response => {
          this.$modal.msgSuccess("新增成功");
          this.resetForm("applyForm");
          this.applyOpen = false;
          this.getApplyList();
        });
      } else {
        this.$message({ message: '请选择至少一个模块', type: 'warning' })
      }
    },
    closeApply() {
      this.applyDetailOpen = false
      this.IsJuanDetail = false
      this.IsJianDetail = false
      this.IsDzwjDetail = false
      this.IsXmDetail = false
      this.enableOperate = ''
      this.myDataChecked = []
      this.ApplyDetailData = []
      // this.applyDetailData=[]
    },
    //关闭设置规则
    closeSetRuleDialog() {
      this.setRuleOpen = false;
    },
    //关闭分类方法
    closeClassifyDialog() {
      this.classifyOpen = false;
    },
    //设置规则弹窗
    setRuleTap(row) {
      this.setRuleOpen = true
      this.addParams = {
        cateIsType: "2",
        queryAddParams: {
          categoryId: this.queryParams.id,
          groupId: this.queryParams.groupId,
          type: this.metaType
        },
        row: row
      }
    },
    //分类方法
    classifyTap() {
      console.log(this.queryParams, "sdkjfklsdj")
      this.classifyOpen = true
      this.addParams = {
        cateIsType: "2",
        queryAddParams: {
          categoryId: this.queryParams.id,
          groupId: this.queryParams.groupId,
          type: this.metaType
        }
      }
    },

    //添加修改制度树
    treeZdAdd() {
      if (this.parentId == undefined || this.parentId == "") {
        this.$modal.msgWarning('请选择要添加的父节点')
        return false
      }
      this.zdTreeDeitOpen = true
      this.addParams = {
        cateIsType: "2",
        parentId: this.parentId,
        queryAddParams: {
          categoryId: this.queryParams.id,
          groupId: this.queryParams.groupId,
          type: this.metaType
        }
      }
    },
    //制度树关闭方法
    closezdTreeDeitDialog() {
      this.zdTreeDeitOpen = false
    },

    //制度树添加修改成功
    submitzdTrreForm() {
      this.zdTreeDeitOpen = false;
      this.parentId = undefined;
      this.gdfwandbgqxTreePost();
    },

    //制度树修改弹窗
    treeZdUpdate() {
      if (this.parentId == undefined || this.parentId == "") {
        this.$modal.msgWarning('请选择要修改的节点')
        return false
      }
      if (this.parentId == 0) {
        this.$modal.msgWarning('请选择除根节点之外的节点进行修改')
        return false
      }
      this.zdTreeDeitOpen = true
      this.addParams = {
        cateIsType: "2",
        deitInfo: this.deitInfo,
        queryAddParams: {
          categoryId: this.queryParams.id,
          groupId: this.queryParams.groupId,
          type: this.metaType
        }
      }
    },
    //删除制度树
    treeZdDelete() {

      var that = this;
      if (this.deitInfo.id != undefined) {

        getzd2(this.deitInfo.id).then(res => {
          console.log(this.deitInfo, "sdkljfklsd")
          if (res.code == "200") {
            this.$modal.confirm('是否确认删除显示名称为"' + this.deitInfo.label + '"的数据项？').then(function () {
              gdfwandbgqxEditzd2({
                id: res.data.id,
                name: res.data.name,
                bgqx: res.data.bgqx,
                remark: res.data.remark,
                orderNo: res.data.orderNo,
                isDel: 1
              }).then(res1 => {
                if (res1.code == "200") {
                  that.$modal.msgSuccess("删除成功")
                  that.gdfwandbgqxTreePost();
                } else {
                  that.$modal.msgError("删除失败");
                }
              })
            }).catch(res => {
              console.log("取消")
            })
          }
        }).catch(res => {

        })
      } else {
        that.$modal.msgError("请选择要删除的数据");
      }


    },
    //制度树列表
    gdfwandbgqxTreePost() {
      var that = this;
      gdfwandbgqxTree(this.queryParams.id).then(res => {
        if (res.code == "200") {
          this.gdfwandOptions = res.data;
        }

      })
    },

    //点击制度树
    gdfwandNodeClick(data) {
      this.parentId = data.id;
      this.deitInfo = data;
      this.gettableListPost();
    },
    //获取制度树表格
    gettableListPost() {
      gettable(this.parentId, this.queryParams.id).then(res => {
        if (res.code == "200") {
          this.tableZdData = res.rows;
        }

      }).catch(res => {

      })
    }
  },
}
</script>
<style lang="scss" scoped>
.first {
  li {
    line-height: 50px;
    height: 50px;
    display: flex;
    font-size: 14px;
    color: #606266;
  }

  li>label {
    width: 100px;
    text-align: right;
    margin-right: 10px;
  }
}

.el-dropdown-menu__item label {
  width: 100px !important;
  display: inline-block;
}

.el-select {
  width: 100%;

}

::v-deep.center-input .el-input input {
  text-align: center;
}

.flex {
  display: flex;
  justify-content: flex-end;
  flex-direction: row
}

.margin-top-form {
  margin-top: 30px;
  margin-bottom: 0 !important;
}

ul,
li {
  //margin: 0;
  //padding: 0;
}

.rule-main li {
  float: left;
  // margin: 0 0.6%;
  margin: 0 1.2% 0 0;
}

.select-model {
  width: 19.1%;
}

.fuhao-model {
  //width: 5.06%;
  width: 10%;
}

.transfer-box {
  display: flex;

  .transfer-box-left {
    border: 2px solid black;
    border-radius: 10px;
    width: 40%;
    height: 240px;
    overflow-y: scroll;
    margin-left: 20px;

    .box-ul {
      list-style: none;
      line-height: 1.5em;
    }
  }

  .transfer-box-center {
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  .transfer-box-right {
    border: 2px solid black;
    border-radius: 10px;
    width: 40%;
    height: 240px;
    overflow-y: scroll;
    margin-left: 20px;

    .box-ul {
      list-style: none;
      line-height: 1.5em;
    }
  }

  .box-title-icon {
    color: #f0463f;
  }
}</style>
